package sv.com.seguros.web.taglib;

import org.apache.commons.lang.StringUtils;
import org.apache.taglibs.standard.tag.common.core.OutSupport;

public class JavascriptOutTag extends OutSupport {

	private static final long serialVersionUID = 2688553318878015610L;

	public JavascriptOutTag(){
		super();
		this.escapeXml = false;
	}
	
	public void setValue(Object value) {
		if(value instanceof String){
			String string = StringUtils.trimToEmpty((String) value);
			string = StringUtils.replace(string, "\\", "\\\\");
			string = StringUtils.replace(string, "\r\n", "\\r\\n");
			string = StringUtils.replace(string, "\n\r", "\\n\\r");
			string = StringUtils.replace(string, "\r", "\\r");
			string = StringUtils.replace(string, "\n", "\\n");
			string = StringUtils.replace(string, "\"", "\\\"");
			string = StringUtils.replace(string, "'", "\\'");
			value = string;	
		}
        this.value = value;
    }
	
	// for tag attribute
    public void setDefault(String def) {
        this.def = def;
    }
        
    // for tag attribute
    public void setEscapeXml(boolean escapeXml) {
        this.escapeXml = escapeXml;
    }
}
